package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/number-of-subarrays-with-gcd-equal-to-k/
 * @create 2025/11/13 16:20
 * @since JDK17
 */

public class Solution55 {
    int gcd(int x, int y) {
        return y == 0 ? x : gcd(y, x % y);
    }
    public int subarrayGCD(int[] nums, int k) {
        int n = nums.length, ans = 0, g = 0;
        for (int i = 0; i < n; i++) {
            g = 0;
            for (int j = i; j < n; j++) {
                g = gcd(g, nums[j]);
                if (g == k) {
                    ans++;
                }
            }
        }

        return ans;
    }
}
